﻿//抵押物区位状况通用下拉框的获取
var uri = document.location.search;//接收页面传值
var i = uri.lastIndexOf("?") + 1;//获取问号前面的值
var P_ReportNumber = uri.substr(i);//截取问号前面的值
$(function () {
    ///判断状态去取消按钮
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Personal/selectbyP_ReportNumberss",
        data: {
            P_ReportNumber: P_ReportNumber
        },
        async: false,
        //contentType: 'application/json',
        success: function (data, status) {
            if (status == "success") {
                if (data != null) {
                    if (data.T_State != 1) {
                        $("#jbSub").remove();
                    }
                }
            }
        }
    })

    $.ajax({
        type: "get",
        url: ApiUrl + "api/Dictionary/GetDictionaryList",
        data: {
            Dmenuid: [2, 3, 4, 5, 6,42]
        },
        async: false,
        success: function (data, status) {
            if (status == "success") {
                $("option").remove();
                $(data).each(function (i, obj) {
                    $(obj).each(function (j, item) {
                        switch (item.Dmenuid) {
                            case 2:
                                $("#T_TrafficID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 3:
                                $("#T_NatureID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 4:
                                $("#T_DwellingID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 5: 
                                $("#T_InfrastructureID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 6:
                                $("#T_SupportingID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 42:
                                $("#T_SurroundID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                        }
                    })
                })
            }
        }
    })
})

//抵押物区位状况
function Zone() {
    var T_ReportNumber = P_ReportNumber//报告号的获取
    var T_Master = $("#T_Master").val();                      //（小区四至）东至
    var T_South = $("#T_South").val();                       //（小区四至）南至
    var T_Western = $("#T_Western").val();                     //（小区四至）西至
    var T_North = $("#T_North").val();                       //（小区四至）北至    
    var T_TrafficID = $("#T_TrafficID option:checked").attr("value");       //交通便捷度编号
    var T_Traffic = $("#T_Traffic").val();                     //交通便捷情况
    var T_NatureID = $("#T_NatureID option:checked").attr("value");        //自然人文环境编号
    var T_Nature = $("#T_Nature").val();                      //自然人文环境的情况
    var T_DwellingID = $("#T_DwellingID option:checked").attr("value");      //居住社区成熟度编号
    var T_Dwelling = $("#T_Dwelling").val();                    //居住社区成熟情况
    var T_Infrastructure = $("#T_Infrastructure").val();//基础设施配套情况
    var T_InfrastructureID = $("#T_InfrastructureID option:checked").attr("value");//基础设施配套编号
    var T_SurroundID = $("#T_SurroundID option:checked").attr("value");    //配套设施编号
    var T_SupportingID = $("#T_SupportingID option:checked").attr("value");
    var T_Explain = $("#T_Explain").val();                     //有关说明
    //  var Z_state = "暂无";                                    //状态
    var parms = {
        T_ReportNumber: T_ReportNumber,
        T_Master: T_Master,     //（小区四至）东至
        T_South: T_South,     //（小区四至）南至
        T_Western: T_Western,     //（小区四至）西至
        T_North: T_North,     //（小区四至）北至    
        T_TrafficID: T_TrafficID,     //交通便捷度编号
        T_Traffic: T_Traffic,     //交通便捷情况
        T_NatureID: T_NatureID,     //自然人文环境编号
        T_Nature: T_Nature,      //自然人文环境的情况
        T_DwellingID: T_DwellingID,     //居住社区成熟度编号
        T_Dwelling: T_Dwelling,     //居住社区成熟情况
        T_InfrastructureID: T_InfrastructureID,     //基础设施配套情况编号
        T_SurroundID: T_SurroundID,    //基础设施配套情况
        T_Explain: T_Explain,     //配套设施编号
        T_Infrastructure: T_Infrastructure,
        T_SupportingID: T_SupportingID,
    }
    $.ajax({
        type: "post",
        url: ApiUrl + "api/Zone/Postinsert",
        data: parms,
        success: function (data, status) {
            if (status == "success") {
                if (data == true) {
                    layer.msg('保存成功!', { icon: 1, time: 1000 });
                }
                else {
                    layer.msg('保存失败!', { icon: 2, time: 1000 });
                }
            }
        }
    })
}
//数据回填
$(function () {
    //根据报告号判断抵押物区位状况有没有以前填写的数据如果有回填
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Personal/SelectProspecting",
        data: { T_ReportNumber: P_ReportNumber },
        async: false,
        success: function (data, status) {
            if (status == "success") {
                if (data.Message == "error") {
                    layer.alert("服务器请求失败!请联系管理员！！", { icon: 2, });
                }//待
                //抵押物区位状况
                if (data.Collateral_Zone != null && data.Collateral_Zone != undefined) {
                    $("#T_SurroundID").val(data.Collateral_Zone.T_SurroundID);
                    $("#T_Master").val(data.Collateral_Zone.T_Master);
                    $("#T_South").val(data.Collateral_Zone.T_South);
                    $("#T_Western").val(data.Collateral_Zone.T_Western);
                    $("#T_North").val(data.Collateral_Zone.T_North);
                    $("#T_TrafficID").val(data.Collateral_Zone.T_TrafficID);
                    $("#T_Traffic").val(data.Collateral_Zone.T_Traffic);
                    $("#T_NatureID").val(data.Collateral_Zone.T_NatureID);
                    $("#T_Nature").val(data.Collateral_Zone.T_Nature);
                    $("#T_DwellingID").val(data.Collateral_Zone.T_DwellingID);
                    $("#T_Dwelling").val(data.Collateral_Zone.T_Dwelling);
                    $("#T_InfrastructureID").val(data.Collateral_Zone.T_InfrastructureID);
                    $("#T_Infrastructure").val(data.Collateral_Zone.T_Infrastructure);
                    $("#T_SupportingID").val(data.Collateral_Zone.T_SupportingID);
                    $("#T_Explain").val(data.Collateral_Zone.T_Explain);
                }
            }
        }
    })


})